﻿using System;

namespace Patterns.Proxy {
    public static class AbstractExample {

        public static void Run() {
            // Create proxy and request a service
            Proxy proxy = new Proxy();
            proxy.Request();
        }
    }

    // "Subject"
    abstract class Subject {
        public abstract void Request();
    }

    // "RealSubject"
    class RealSubject : Subject {
        public override void Request() {
            Console.WriteLine("Called RealSubject.Request()");
        }
    }

    // "Proxy"
    class Proxy : Subject {
        RealSubject realSubject;

        public override void Request() {
            // Use 'lazy initialization'
            if (realSubject == null) {
                realSubject = new RealSubject();
            }

            realSubject.Request();
        }
    }
}
